import os
import pandas as pd
from pyecharts import options as opts
from pyecharts.charts import WordCloud

# 数据目录
data_dir = '/root/eduhq/result/ads_user_domain/'
# 背景图片
background_image = '/root/eduhq/images/img_2.png'
# 输出图表存放地址
output_path = '/root/eduhq/html/不同域名用户访问统计词云.html'

# 读取用户访问数据
data_file = os.path.join(data_dir, 'domain_access_data.csv')  # 替换为你的数据文件
data = pd.read_csv(data_file)

# 假设数据文件有域名和访问次数列
domain_data = data[['Domain', 'AccessCount']].values.tolist()  # 获取域名和访问次数

# 创建词云图
wordcloud = (
    WordCloud()
    .add(series_name="用户访问统计", data_pair=domain_data)
    .set_global_opts(title_opts=opts.TitleOpts(title="不同域名用户访问统计词云"))
)

# 渲染图表
wordcloud.render(output_path)

print(f"图表已生成并保存到: {output_path}")
